package com.csun.cmny.provider.controller.oldmanApp;

import com.csun.cmny.core.support.BaseController;
import com.csun.cmny.provider.model.domain.OmcAppUserBuildingBind;
import com.csun.cmny.provider.model.dto.oldmanApp.AppOldmanDto;
import com.csun.cmny.provider.model.dto.oldmanApp.AppRoomDto;
import com.csun.cmny.provider.pojo.Building;
import com.csun.cmny.provider.service.*;
import com.csun.cmny.provider.vo.OldManVo;
import com.csun.cmny.util.PublicUtil;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping(value = "/appOldmanManager", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class OmcOldmanManagerController extends BaseController {

    @Resource
    private OldmanService oldmanService;
    @Resource
    private OmcAppUserOldmanBindService omcAppUserOldmanBindService;
    @Resource
    private RoomService roomService;
    @Resource
    private OmcAppUserBuildingBindService omcAppUserBuildingBindService;

    /**
     * 用户绑定老人
     * @param: [appOldmanDto]
     * @return: com.csun.cmny.util.wrapper.Wrapper
     */
    @RequestMapping(value = "/userBindsOldman", method = RequestMethod.POST)
    public Wrapper userBindsOldman(@RequestBody AppOldmanDto appOldmanDto) {

        Integer result = oldmanService.oldmanAppAddOldman(appOldmanDto,getLoginAuthDto());

        return WrapMapper.ok(result);
    }

    /**
     * 修改老人信息
     * @param: [appOldmanDto]
     * @return: com.csun.cmny.util.wrapper.Wrapper
     */
    @RequestMapping(value = "/editAppOldmanInfo", method = RequestMethod.POST)
    public Wrapper editAppOldmanInfo(@RequestBody AppOldmanDto appOldmanDto) {

        Integer result = oldmanService.editAppOldmanInfo(appOldmanDto,getLoginAuthDto());

        return WrapMapper.ok(result);
    }

    /**
     * 查询app用户绑定的老人列表
     * @param: []
     * @return: com.csun.cmny.util.wrapper.Wrapper
     */
    @RequestMapping(value = "/queryBoundOldmanList", method = RequestMethod.POST)
    public Wrapper queryBoundOldmanList() {

        List<OldManVo> vos = oldmanService.queryBoundOldmanList(getLoginAuthDto());

        return WrapMapper.ok(vos);
    }

    /**
     * 用户解绑老人
     * @param: [appOldmanDto]
     * @return: com.csun.cmny.util.wrapper.Wrapper
     */
    @RequestMapping(value = "/userRemovesOldman/{oldmanId}", method = RequestMethod.POST)
    public Wrapper userRemovesOldman(@PathVariable Long oldmanId) {

        Integer result = omcAppUserOldmanBindService.userRemovesOldman(oldmanId,getLoginAuthDto());

        return WrapMapper.ok(result);
    }

    /**
     * 用户添加房间
     * @param: [appRoomDto]
     * @return: com.csun.cmny.util.wrapper.Wrapper
     */
    @RequestMapping(value = "/userAddRoom", method = RequestMethod.POST)
    public Wrapper userAddRoom(@RequestBody AppRoomDto appRoomDto) {

        Integer result = roomService.userAddRoom(appRoomDto,getLoginAuthDto());

        return WrapMapper.ok(result);
    }

    /**
     * 用户查询楼栋id
     * @param: 
     * @return: com.csun.cmny.util.wrapper.Wrapper
     */
    @RequestMapping(value = "/userGetBuilding", method = RequestMethod.POST)
    public Wrapper userGetBuilding() {
        OmcAppUserBuildingBind omcAppUserBuildingBind = omcAppUserBuildingBindService.selectByKey(getLoginAuthDto().getUserId());
        if(PublicUtil.isEmpty(omcAppUserBuildingBind)){
            omcAppUserBuildingBind = new OmcAppUserBuildingBind();
        }
        return WrapMapper.ok(omcAppUserBuildingBind.getBuildingId());
    }
}
